﻿using AIO.Entity;
using AIO.IService.Base;
using Microsoft.AspNetCore.Mvc;

namespace AIO.Api.Controller
{
    [Route("api/[controller]")]
    [ApiController]
    public class AccountController : ControllerBase
    {
        /// <summary>
        /// 仓储
        /// </summary>
        private readonly IRepositoryWrapper _repository;
        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILogger<DepartmentController> _logger;

        public AccountController(IRepositoryWrapper repository
            , ILogger<DepartmentController> logger)
        {
            _repository = repository;
            _logger = logger;
        }

        /// <summary>
        /// 登录验证
        /// </summary>
        /// <param name="LoginName">账户</param>
        /// <param name="LoginPassword">密码</param>
        /// <returns></returns>
        public IActionResult Login(string LoginName,string LoginPassword) 
        {
            try
            {
                Account? account = _repository.AccountRepository.Login(LoginName, LoginPassword);
                if(account==null)
                {
                    return StatusCode(404);
                }
                return Ok(account);
            }
            catch (Exception)
            {

                return StatusCode(500);
            }
            

        }

        [HttpGet]
        public IActionResult GetAll()
        {
            try
            {
                var departmentList = _repository.AccountRepository.GetAllNoBy();
                return Ok(departmentList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"{ex.Message}");
                return StatusCode(500);
            }

        }
    }
}
